﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CollectionPracticeArray
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] monthArray = new string[12]
            {
                "Январь",
                "Февраль",
                "Март",
                "Апрель",
                "Май",
                "Июнь",
                "Июль",
                "Август",
                "Сентяьбрь",
                "Октябрь",
                "Ноябрь",
                "Декабрь"
            };





            //string[] monthArray2 = new string[14];

            //monthArray.CopyTo(monthArray2, 1);

            //foreach (var month in monthArray2)
            //{
            //    Console.WriteLine(month);
            //}





            //string[] monthArray3 = new string[6];

            //Array.Copy(monthArray, monthArray3, 6);

            //foreach(var month in monthArray3)
            //{
            //    Console.WriteLine(month);
            //}

            //Array.Sort(monthArray);
            //Array.Reverse(monthArray);

            //foreach (var month in monthArray)
            //{
            //    Console.WriteLine(month);
            //}

            //Console.WriteLine(Array.IndexOf(monthArray, "Ноябрь"));



            //string[] digitsArray = new string[8]
            //{
            //    "789",
            //    "654",
            //    "891",
            //    "321",
            //    "101",
            //    "423",
            //    "235",
            //    "555"
            //};



            //Array.Sort(digitsArray, new MyMonthCompare());

            //foreach (var digit in digitsArray)
            //{
            //    Console.WriteLine(digit);
            //}
            //Console.WriteLine();



            //Array.Sort(digitsArray, new MyMonthComparerLynq());
            //foreach (var item in digitsArray)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine();

            //Array.Sort(digitsArray);



            //string[] monthArray4 = Array.FindAll(monthArray, x => x[0] == 'А');

            //foreach (var month in monthArray4)
            //{
            //    Console.WriteLine(month);
            //}



            //string[] monthArray5 = Array.FindAll(monthArray, x => x.Length < 4);

            //foreach (var month in monthArray5)
            //{
            //    Console.WriteLine(month);
            //}

            Car car1 = new Car("Mercedes", 10000, "Blue", 1990, "5600");
            Car car2 = new Car("Audi", 20000, "Red", 1992, "A3");
            Car car3 = new Car("Renault", 5000, "Black", 1998, "Duster");
            Car car4 = new Car("BMW", 40000, "Black", 2000, "X5");
            Car car5 = new Car("BMW", 45000, "Red", 2003, "X6");
            Car car6 = new Car("Audi", 35000, "Silver", 1998, "A3");
            Car car7 = new Car("BMW", 33000, "White", 2003, "i3");
            Car car8 = new Car("Mazde", 22000, "White", 2004, "6");
            Car car9 = new Car("Mazde", 24000, "Blue", 2004, "3");


            Car[] carsArray = new Car[9]
            {
                car1,
                car2,
                car3,
                car4,
                car5,
                car6,
                car7,
                car8,
                car9
            };

            Car[] cars30000 = Array.FindAll(carsArray, x => x.Cost > 30000);

            foreach (var car in cars30000)
            {
                Console.WriteLine(car.ToString());
            }

            Console.WriteLine("--------------------");

            Car[] carsAudiBMW = Array.FindAll(carsArray, x => x.Brand == "BMW" || x.Brand == "Audi");

            foreach (var car in carsAudiBMW)
            {
                Console.WriteLine(car.ToString());
            }

            Console.WriteLine("--------------------");

            Car[] carsAudiA3 = Array.FindAll(carsArray, x => x.Model == "A3" && x.Brand == "Audi");

            foreach (var car in carsAudiA3)
            {
                Console.WriteLine(car.ToString());
            }

            Console.WriteLine("--------------------");

            Car[] carsRed15to50NotAudi = Array.FindAll(carsArray, x => x.Cost >= 15000 && x.Cost <= 50000 && x.Brand != "Audi" && x.Color == "Red");
            foreach (var car in carsRed15to50NotAudi)
            {
                Console.WriteLine(car.ToString());
            }
        }

    }

    //class MyMonthCompare : IComparer<string>
    //{
    //    public int Compare(string x, string y)
    //    {
    //        if (x[x.Length - 1] < y[y.Length - 1])
    //            return -1;
    //        else if (x[x.Length - 1] == y[y.Length - 1])
    //            return 0;
    //        return 1;
    //    }
    //}

    //class MyMonthComparerLynq : IComparer<string>
    //{
    //    public int Compare(string x, string y)
    //    {
    //        string xRev = x.Reverse().ToString();
    //        string yRev = y.Reverse().ToString();

    //        if (xRev[0] < yRev[0])
    //            return -1;
    //        else if (xRev[0] == yRev[0])
    //            return 0;
    //        return 1;
    //    }
    //}

    class Car
    {
        private string brand;
        private int cost;
        private string color;
        private int year;
        private string model;

        public string Brand
        {
            get
            {
                return brand;
            }
            set
            {
                brand = value;
            }
        }

        public int Cost
        {
            get
            {
                return cost;
            }
            set
            {
                cost = value;
            }
        }

        public string Color
        {
            get
            {
                return color;
            }
            set
            {
                color = value;
            }
        }

        public int Year
        {
            get
            {
                return year;
            }
            set
            {
                year = value;
            }
        }

        public string Model
        {
            get
            {
                return model;
            }
            set
            {
                model = value;
            }
        }
        public Car(string brand, int cost, string color, int year, string model)
        {
            Brand = brand;
            Cost = cost;
            Color = color;
            Year = year;
            Model = model;
        }

        public override string ToString()
        {
            StringBuilder resultString = new StringBuilder();
            resultString.AppendFormat("Car info {0} {1} {2} {3} {4}", Brand, Cost, Color, Year, Model);
            string result = resultString.ToString();
            return result;
        }

    }
}
